<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<script type="text/javascript">

	$(document).ready(function() {
		$("#replyBtn").click(function() {
			//alert($("#content").val());
			$.ajax({
				type : "POST",
				url : "gallery.do",
				data : "mode=reply_write&gallery_no=${param.no}&m_uid=${sessionScope.mvo.uId }&content="+ $("#content").val()+ "&restep="+ $("#restep").val(), dataType : "json",


				success : function(jsonData) { // data 변수로 json 입력된다.						
				// function 을 인자값으로 하여 table 처리 
					$("#gallery_reply").html(function() {
						var level = "${sessionScope.mvo.level }"; // 관리자권한 추가
						
						var obj = jsonData.list;
						var table = "<table  width = '780px' border = '0' align='center' style='border-collapse: collapse; border-top-style: none;'>";
						
						for (i = 0; i < obj.length; i++) {
							var id = "${sessionScope.mvo.uId }";
							table += "<tr style='border: 0'>";
							table += "<td width='10'><input type='hidden' id='restep' value='"+obj[i].RESTEP+"'></td>";
							table += "<td style='border: 0' width='30'>→</td>";
							table += "<td style='border: 0' width='100'>"+ obj[i].M_NICKNAME + "</td>";
							table += "<td style='border: 0' width='600'>"+ obj[i].CONTENT+ "</td>";
							table += "<td style='border: 0' width='50'>"+ obj[i].W_DATE + "</td>";
																						
							if (obj[i].M_UID == id || level == "99") {
								table += "<td style='border: 0' width='50'>";
								table += "<a href='gallery.do?mode=reply_delete&no="+ obj[i].REPLY_NO+"&uId=${sessionScope.mvo.uId}&ref=${requestScope.cvo.gvo.no}&restep="+ obj[i].RESTEP + "'>삭제</a>";
								table += "</td>";
							} // if
	
							table += "</tr>";
						} // for
							table += "</table>";
							return table;
					});//html
	
		
					$("#content").val("");
				}// success
			}); // ajax 
		});// replyBtn click

	});// document
</script>
<c:set var="content" value="${requestScope.cvo.gvo }"></c:set>
<table>
	<tr>
		<td colspan="7"><img
			src="/img/upload_gal/${content.orgImgName }" width="800"></td>
	</tr>
	<tr>
		<td>조회수</td>
		<td>${content.count }</td>
		<td>추천수</td>
		<td>${content.wow }</td>
		<td>작성일</td>
		<td>${content.w_date }</td>
		<!--------------		추천관련 시작		-------------->
		<!--     로그인을 했는가  	  &&     추천을 했던 사람이었는가	  && 		현재 게시물을 작성한 사람인가 					  -->
		<c:if test="${sessionScope.mvo.uId!=null && requestScope.cvo.wow_check==null && sessionScope.mvo.uId!=requestScope.cvo.gvo.memberVO.uId }">
		<td><a href="gallery.do?mode=wow&no=${requestScope.cvo.gvo.no }&memberVO.uId=${sessionScope.mvo.uId}"><font color="#CCD000">WoW!!</font></a></td>
		</c:if>
	<!--------------		추천관련 끝		-------------->
	</tr>
	<tr>
		<td colspan="7">${content.title }</td>
	</tr>
	<tr>
		<td colspan="7">${content.contents }</td>
	</tr>

	<tr>
		<td colspan="7" height="60">
			<!-- 목록보기와 띄워놓기 위해 사용함 -->
		</td>
	</tr>

	<tr>
		<td align="left" colspan="7"><a href="gallery.do?mode=list&category=${content.category }">목록보기</a>
			<!-- 관리자 권한을 비교하여 삭제버튼 출력 -->
			<c:if test="${ sessionScope.mvo.level=='99' }">
			<a href="gallery.do?mode=delete&no=${content.no }&img=${content.orgImgName }&thumb=${content.thumbImgName}&admin=${sessionScope.mvo.level}&category=${content.category }">관리자삭제</a>  
			</c:if>	
		</td>
	</tr>
</table>

<table>
	<c:if test="${sessionScope.mvo.uId!=null }">
		<tr style="border: 0">
			<td colspan="4" style="border: 0"><textarea
					style="width: 690px; height: 50px;" rows="2" id="content"></textarea>
			</td>
			<td><input type="Button" id="replyBtn" value="댓글입력"
				style="width: 100px; height: 50px;"></td>
		</tr>
	</c:if>
</table>

<table>
	<tr>
		<td colspan="7" height="40">
			<!-- 목록보기와 띄워놓기 위해 사용함 -->
		</td>
	</tr>
</table>


<div id="gallery_reply">
	<table width="780px" border="0" align="center"
		style="border-collapse: collapse; border-top-style: none;">

		<c:forEach items="${requestScope.cvo.list }" var="reply">
			<tr style="border: 0">
				<td><input type="hidden" id="restep" value="${reply.RESTEP }"></td>
				<td style="border: 0" width="30">→</td>
				<td style="border: 0" width="100">${reply.M_NICKNAME}</td>
				<td style="border: 0" width="600">${reply.CONTENT}</td>
				<td style="border: 0" width="50">${reply.W_DATE}</td>
				<c:if test="${reply.M_UID==sessionScope.mvo.uId || sessionScope.mvo.level=='99' }">
					<!-- <td style="border: 0" width="50" id="updateReply" >수정</td> -->
					<td style="border: 0" width="50"><a
						href="gallery.do?mode=reply_delete&no=${reply.REPLY_NO}&uId=${sessionScope.mvo.uId }&ref=${requestScope.cvo.gvo.no}&restep=${reply.RESTEP }">삭제</a>
					</td>
				</c:if>
			</tr>
		</c:forEach>
		<tr>
			<td colspan="7" height="40">
				<!-- 목록보기와 띄워놓기 위해 사용함 -->
			</td>
		</tr>
	</table>
</div>
